package com.yycx.module.user.provider.service.impl;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.base.service.impl.BaseServiceImpl;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.module.user.provider.mapper.SysVersionMapper;
import com.yycx.module.user.client.entity.SysVersion;
import com.yycx.module.user.provider.service.SysVersionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 版本控制 实现类
 *
 * @author flyme
 * @date 2019-10-19
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysVersionServiceImpl extends BaseServiceImpl<SysVersionMapper, SysVersion> implements SysVersionService {


    @Override
    public ResultBody beforePageList(CriteriaQuery<SysVersion> cq, SysVersion sysVersion, EntityMap requestMap) {
        cq.eq(SysVersion.class,"verNo");
        cq.eq(SysVersion.class,"verName");
        cq.orderByDesc("createTime");
        return super.beforePageList(cq, sysVersion, requestMap);
    }

    @Override
    public ResultBody getByVeCode(String veCode) {
        CriteriaQuery cq = new CriteriaQuery(SysVersion.class);
        cq.select(SysVersion.class, "*");
        cq.eq(SysVersion.class, "verCode", veCode);
        cq.orderByDesc("verNo");
        cq.last("limit 0,1");
        return baseGet(cq);
    }

    @Override
    public ResultBody getLastVersion() {
        CriteriaQuery cq = new CriteriaQuery(SysVersion.class);
        cq.select(SysVersion.class, "*");
        cq.orderByDesc("createTime");
        cq.limit(1);
        return baseGet(cq);
    }

}
